/*
    SEL - Simple DirectMedia Layer Extension Library
    Copyright (C) 2001 Matej Knopp <knopp@users.sf.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#ifndef __sel_resources_h__
#define __sel_resources_h__

#include "resource.h"

/*
 * This file contains the default resource types
 */

namespace SEL
{
class Surface;

//TODO: Should the clone() functions be constant?

//! The ResourceSurface class reprensents a resource with Surface data.
/*!
  The ResourceSurface can have one optional property called "format" that
  specifies the source image format type. This is optional (it's determined
  automatically), unless you want to use the TGA image format which
  needs to be specified explicitely.
  
  The type identifier for the ResourceSurface is `surface'.
 */
class ResourceSurface : public Resource
{
public:
	//! Create a new resource.
	ResourceSurface (const std::string &name,
			 const std::string &location,
			 const ResourceProperties &properties);

	//! Destroy the resource.
	virtual ~ResourceSurface ();

	//! Load the image from RWops.
	virtual void load (RWops &ops);
	
	//! Free the image data (if any).
	virtual void free ();
	
	//! Query whether the image is loaded.
	virtual bool loaded () const		{ return m_surface != NULL; }
	
	//! 
	virtual bool hasData ()	const		{ return true; }
	
	//! Return pointer to the surface data (or NULL if none).
	virtual void *data ()			{ return (void*)m_surface; }

	//! Return const pointer to the surface data (or NULL if none).
	virtual const void *data () const	{ return (void*)m_surface; }
	
	//! Return pointer to the surface data (or NULL if none).
	Surface *surface () 			{ return m_surface; }

	//! Return const pointer to the surface data (or NULL if none).
	const Surface *surface () const		{ return m_surface; }
	
	//! Clone the surface data.
	/*!
	  This makes a copy of the current surface and returns it.
	  The new created surface is independent of the resource
	  and thus must be freed manually.
	 */
	Surface *clone ();

protected:
	Surface *m_surface;
	char m_format [3];
};

//! Retrieve the surface from \a resource or throw an error if the type of
//! the resource is invalid.
Surface * getSurface (Resource * resource);

class Font;

//! The ResourceFont class represents a resource with Font data.
/*!
  The type identifier for the ResourceFont is `font'.
  
  The font resource has these arguments:
  - \a format - optional - specifies the source image format type. See the ResourceSurface
  class for more information.
  - \a map - required - the order of characters in the source image.
  - \a space_width - optional - the width of the space. Default value is 8 pixels.
  - \a min_gap_width - optional - the minimal count of empty lines between two
    characters. The default value is 2.
  - \a alpha_treshold - optional - the minimal value of a pixel in alpha 
    channel that is considered opaque. The default value is 1.
  - \a h_spacing - optional - the additional spacing between characters. The
    default value is 1.
  - \a v_spacing - optional - the additional spacing between lines. The default
    value is 0.
 */
class ResourceFont : public ResourceSurface 
{
public:
	//! Create a new font resource.
	ResourceFont (const std::string &name,
		      const std::string &location,
		      const ResourceProperties &properties);

	//! Destroy the font resource and the font (if loaded).
	virtual ~ResourceFont ();
	
	//! Load the font from RWops.
	virtual void load (RWops &ops);
	
	//! Free the font data (if any).
	virtual void free ();
	
	//! Query whether to font is loaded.
	virtual bool loaded () const		{ return m_font != NULL; }
	
	//! 
	virtual bool hasData () const		{ return true; }
	
	//! Return pointer to the font data (or NULL if none).
	virtual void *data ()			{ return (void*)m_font; }

	//! Return const pointer to the font data (or NULL if none).
	virtual const void *data () const	{ return (void*)m_font; }
	
	//! Return pointer to the font data (or NULL if none).
	Font *font () 				{ return m_font; }

	//! Return const pointer to the font data (or NULL if none).
	const Font *font () const		{ return m_font; }
	
	//! Clone the font data.
	/*!
	  This makes a copy of the current font and returns it. 
	  The new created font is independent of the resource and thus
	  must be freed manually.
	 */
	Font *clone ();

protected:
	Font *m_font;
};

//! Retrieve the font from \a resource or throw an error if the type of
//! the resource is invalid.
Font * getFont (Resource * resource);


//! Register default resource types.
/*!
  You must call this before using default resource types.
 */
void resourcesInit ();

} // namespace SEL

#endif // __sel_resources_h__
